package bma.common.langutil.jmshell.command;

import java.util.ArrayList;
import java.util.List;

import bma.common.langutil.jmshell.JMShellUtil;
import bma.common.langutil.jmshell.Session;
import bma.common.langutil.jmshell.cmdopt.CommandOptionParser;

public class ListCommand extends AbstractSimpleCommandProcessor {
	/**
	 * 
	 */
	protected CommandSet commandSet;
	protected List<String> preset;

	public ListCommand() {
		this(null);
	}

	public ListCommand(CommandSet cset) {
		super("ls");
		this.commandSet = cset;
		addAlias("ll");
	}

	public CommandSet getCommandSet() {
		return commandSet;
	}

	public List<String> getPreset() {
		return preset;
	}

	public void setPreset(List<String> preset) {
		this.preset = preset;
	}
	
	public void addPreset(String cmd) {
		if(this.preset==null) {
			this.preset = new ArrayList<String>();
		}
		this.preset.add(cmd);
	}

	@Override
	public CommandOptionParser createCommandOption(Session session) {
		CommandOptionParser r = new CommandOptionParser();
		return r;
	}

	@Override
	public boolean processCommand(Session session, String cmd,
			CommandOptionParser options) {
		ArrayList<String> list = new ArrayList<String>(1 + (preset == null ? 0
				: preset.size()));
		list.add("ls");
		if (preset != null) {
			list.addAll(preset);
		}
		return JMShellUtil.listCommand(session, commandSet, options, list);
	}

}